package com.wangjiacai.utils.ali.tts;

import com.alibaba.nls.client.protocol.OutputFormatEnum;
import com.alibaba.nls.client.protocol.SampleRateEnum;
import com.alibaba.nls.client.protocol.SpeechReqProtocol;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;

@Slf4j
public class SpeechSynthesizer extends SpeechReqProtocol{

    private static final Integer DEFAULT_VOICE_VOLUME = 50;

    public SpeechSynthesizer(String appKey) {
        this.payload = new HashMap();
        this.header.put("namespace", "SpeechSynthesizer");
        this.header.put("name", "StartSynthesis");
        this.setSampleRate(SampleRateEnum.SAMPLE_RATE_16K);
        this.setVolume(DEFAULT_VOICE_VOLUME);
        this.setAppKey(appKey);
        this.setFormat(OutputFormatEnum.WAV);
    }

    public SpeechSynthesizer(String appKey,OutputFormatEnum outputFormatEnum) {
        this.payload = new HashMap();
        this.header.put("namespace", "SpeechSynthesizer");
        this.header.put("name", "StartSynthesis");
        this.setSampleRate(SampleRateEnum.SAMPLE_RATE_16K);
        this.setVolume(DEFAULT_VOICE_VOLUME);
        this.setAppKey(appKey);
        this.setFormat(OutputFormatEnum.MP3);
    }

    public void setVoice(String voice) {
        this.payload.put("voice", voice);
    }

    public void setText(String text) {
        this.payload.put("text", text);
    }

    public void setFormat(OutputFormatEnum format) {
        this.payload.put("format", format.getName());
    }

    public void setSampleRate(SampleRateEnum sampleRate) {
        this.payload.put("sample_rate", sampleRate.value);
    }

    public void setSampleRate(int sampleRate) {
        this.payload.put("sample_rate", sampleRate);
    }

    public void setVolume(int volume) {
        this.payload.put("volume", volume);
    }

    public void setSpeechRate(int speechRate) {
        this.payload.put("speech_rate", speechRate);
    }

    public void setPitchRate(int pitchRate) {
        this.payload.put("pitch_rate", pitchRate);
    }

    public void setMethod(int method) {
        this.payload.put("method", method);
    }

    public void setTaskId(String taskId){
        super.setTaskId(taskId);
    }

}
